home *** CD-ROM | disk | FTP | other *** search
- Path: news.cybercom.net!usenet
- From: nield@cybercom.net (John Nield)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: returning an array from function
- Date: Wed, 03 Apr 1996 21:33:01 GMT
- Organization: Cyber Access Internet Services (617) 396-0491
- Message-ID: <4juqrp$250@orion.cybercom.net>
- References: <4jstd8$kh0@news1.sunbelt.net>
- Reply-To: nield@cybercom.net
- NNTP-Posting-Host: dial2-9.cybercom.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- bourne@infoave.net (Rick Huebner) wrote:
-
- >I have looked in several texts and looked through the faq for this question
- >and can't find a reference for my answer. I am trying to return an array, or
- >a pointer to the array, from a function. I have seen several examples of
- >returning a pointer, but it doesn't seem to work for me. My function is going
- >to return an array of integers where 1-80 of them will be significant. The
- >calling function will know how many integers are expected and will read them
- >off the array....If I can get the pointer back to the array. A friend of mine
- >told me to just make the array a global, but I don't want to do that if I can
- >help it. I would even resort to a recursive function that will pass the
- >integers back one at a time if that is possible. Does anyone have any
- >suggestions? I am open to anything and will go looking if you can tell me
- >where(hopefully online somewhere).
-
- >Thanks...
-
- #define ARRAY_SIZE 80
-
- main()
- {
- int array[ARRAY_SIZE];
-
- fillarray(array);
- }
-
- void fillarray(int *array_pntr)
- {
- int i;
-
- for (i=0; i < ARRAY_SIZE; i++)
- {
- printf("\nEnter an Integer:");
- scanf("%d", &array_pntr[i]); /* write to memory address of element i
- of the array */
- }
- /* you dont need to return anything */
- }
-
- I hope that's what you ment by your question.
-
- ;jn
-
-